package net.homelinux.chaoswg.io.renga.krypto.animations.Mult;

import net.homelinux.chaoswg.io.renga.core.animations.State;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.Unsigned128Bit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.Unsigned16Bit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.Unsigned32Bit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.Unsigned64Bit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.Unsigned8Bit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBit;
import net.homelinux.chaoswg.io.renga.krypto.datatypes.numerical.UnsignedNBitFactory;

public class MultState implements State {
    UnsignedNBit factor0 = new Unsigned8Bit();
    UnsignedNBit factor1 = new Unsigned8Bit();
    UnsignedNBit result = new Unsigned8Bit();
    
    public MultState () {}
    
    public MultState (UnsignedNBit factor0, UnsignedNBit factor1) {
        this.factor0 = factor0;
        this.factor1 = factor1;
        
        if (factor0 instanceof Unsigned8Bit) {
            this.result = new Unsigned8Bit ();
        } else if (factor0 instanceof Unsigned16Bit) {
            this.result = new Unsigned16Bit ();
        }else if (factor0 instanceof Unsigned32Bit) {
            this.result = new Unsigned32Bit ();
            
        } else if (factor0 instanceof Unsigned64Bit) {
            this.result = new Unsigned64Bit ();
            
        } else if (factor0 instanceof Unsigned128Bit) {
            this.result = new Unsigned128Bit ();
        }
    }
    
    public UnsignedNBit getFactor0() {
        return factor0;
    }
    public void setFactor0(UnsignedNBit factor0) {
        this.factor0 = factor0;
    }
    public UnsignedNBit getFactor1() {
        return factor1;
    }
    public void setFactor1(UnsignedNBit factor1) {
        this.factor1 = factor1;
    }
    public UnsignedNBit getResult() {
        return result;
    }
    public void setResult(UnsignedNBit result) {
        this.result = result;
    }

    public void setOperand(final int slot, final Object value) {
        if (value instanceof UnsignedNBit) {
            switch (slot) {
                case 0:
                    factor0 = ((UnsignedNBit)value);
                    result = UnsignedNBitFactory.createUnsignedNBitFactory().get(factor0.getN());
                    break;
                case 1:
                    factor1 = ((UnsignedNBit)value);
                    result = UnsignedNBitFactory.createUnsignedNBitFactory().get(factor1.getN());
                    break;
            }
        }
    }
}
